<%-- 
    Document   : BuyAll
    Created on : 2020-4-19, 17:29:09
    Author     : zhang
--%>

<%@page import="entity.Address"%>
<%@page import="dao.AddressDao"%>
<%@page import="java.util.List"%>
<%@page import="dao.BookDao"%>
<%@page import="entity.Book"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Iterator"%>
<%@page import="service.FindCart"%>
<%@page import="java.util.HashMap"%>
<%@page import="entity.Member"%>
<%@page import="dao.MemberDao"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        
        <h1>确认订单</h1>
        <div style="position: absolute;left:300px;top:50px"><a href="Cart.jsp">返回购物车</a></div>
        <%
            Member member=new MemberDao().getMemberByName((String)session.getAttribute("username"));
            HashMap<Integer,Integer> map=new FindCart().findAllCart(member.getId());
            
            float price=0;
            
            Iterator it = map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                Integer bookId = (Integer)entry.getKey();
                Integer count = (Integer)entry.getValue();
            
 
            Book book=new BookDao().getBookById(bookId);
            
        %>
       
            <div>
                <h3><%=book.getBookName()%></h3>
                <div style="width: 200px;height:300px;border:1px solid #000">
                    <img src="img/<%=book.getCover()%>" width="200px" height="300px" alt="<%=book.getBookName()%>">
                </div>
                <div style="width: 300px;height:250px" >
                    <p>编号：<%=book.getId()%></p>
                    <p>作者：<%=book.getAuthor()%></p>
                    <p>数量：<%=count%></p>
                    <p>单价：<span id="price"><%=book.getPrice()%></span></p>                   
                    <a href="gbbi?id=<%=book.getId()%>">查看更多</a>
                </div>
            </div>
                
                <%
                    price+=count*book.getPrice();
                    }
                %>
            <h1>实付款：<%=price%></h1>
            <form action="bas" method="post">
            <h3>选择收货地址：</h3><br>
            <%
                
                List<Address> list=new AddressDao().getAllAddress(member.getId());
                for(int i=0;i<list.size();i++){
            %>
            <input type="radio" name="address" value="<%=list.get(i).getId()%>">
            <div>
                详细地址：<%=list.get(i).getAddress()%><br>
                收件人：<%=list.get(i).getAddressee()%><br>
                电话：<%=list.get(i).getPhone()%><br>
                邮编：<%=list.get(i).getZipcode()%>
            </div><br>
            <%
                }
            %>
            <button>支付</button>
        </form>
    </body>
</html>
